package com.chengh.nami.core.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * springDoc配置文件
 *
 * @author chengh
 */
@Configuration
public class SpringDocConfig {

    /**
     * token的头
     */
    private static final String headerName = "Authorization";


    @Bean
    public OpenAPI namiOpenAPI() {
        Components components = new Components();
        components.addSecuritySchemes(headerName,
                new SecurityScheme()
                        .type(SecurityScheme.Type.APIKEY)
                        .scheme("basic")
                        .name(headerName)
                        .in(SecurityScheme.In.HEADER)
                        .description("请求头,携带token")
        );
        return new OpenAPI()
                .components(components)
                .info(apiInfo());
    }


    private Info apiInfo() {
        Contact contact = new Contact();
        contact.setEmail("2820304663@qq.com");
        contact.setName("cheng");
        contact.setUrl("https://gitee.com/MRChengh");
        return new Info()
                .title("NAMI接口文档")
                .version("1.0")
                .contact(contact)
                .description("啦啦啦啦")
                .license(new License().name("Apache 2.0").url("http://springdoc.org"));
    }

    @Bean
    public GroupedOpenApi publicApi() {
        return GroupedOpenApi.builder()
                .group("system")
                .pathsToMatch("/system/**")
                .build();
    }
}
